package com.example.blog.config;

import com.example.blog.exception.BusinessException;
import com.example.blog.utils.IpUtil;
import com.example.blog.utils.RedisStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.BindException;


//过滤器  所有请求进行之前都会被过滤一遍,但不是阻止请求
@Component
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {

     @Autowired
    RedisStorage redisStorage;

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String token = request.getHeader("token");
//        System.out.println(token);
        if(!StringUtils.hasText(token)) {
            //放行，让后面的过滤器执行
            filterChain.doFilter(request, response);
            return;
        }
        // 2解析token
        //放行，让后面的过滤器执行
        filterChain.doFilter(request, response);
    }
}



